//package ma.ensao.egicom.core.services.implementations;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import ma.ensao.egicom.core.dao.interfaces.ClientDao;
//import ma.ensao.egicom.core.dto.ClientDto;
//import ma.ensao.egicom.core.model.Client;
//import ma.ensao.egicom.core.services.interfaces.ClientService;
//import ma.ensao.egicom.core.util.ClientKeyUtil;
//
//import org.scub.foundation.framework.base.exception.TechnicalException;
//import org.scub.foundation.framework.base.mapping.util.MapperDozerBean;
//import org.scub.foundation.framework.base.messagesource.MessageSourceUtil;
//import org.scub.foundation.framework.core.oval.validator.IntegrityValidator;
//
//public class ClientServiceImpl implements ClientService {
//    
//    private ClientDao clientDao;
//
//    private MapperDozerBean mapperDozerBean;
//
//    private MessageSourceUtil messageSourceUtil;
//
//    private IntegrityValidator integrityValidator;
//
//    @Override
//    public ClientDto ajouterOuModifierClient(ClientDto clientDto) {
//
//        Client client = new Client();
//        if (clientDto.getId() != null) {
//            client = clientDao.getClientById(clientDto.getId());
//            integrityValidator.assertNotNull(ClientKeyUtil.MESSAGE_ERROR_SAVE_CONTACT_CONTACT_TO_UPDATE_NOT_FOUND, client);
//        }
//
//        mapperDozerBean.map(clientDto, client);
//        final String nom = clientDto.getNom();
//        client.setLastname(nom);
//        final String email = clientDto.getEmail();
//        client.setEmail(email);
//        final String prenom = clientDto.getPrenom();
//        client.setFirstname(prenom);
//
//        if (clientDto.getId() == null) {
//            clientDao.createClient(client);
//        }
//
//        return mapperDozerBean.map(client, ClientDto.class);
//    }
//
//    @Override
//    public void deleteClient(Long idClient) {
//        final Client clientToDelete = clientDao.getClientById(idClient);
//        clientDao.deleteClient(clientToDelete);
//    }
//
//    @Override
//    public ClientDto getClientById(Long id) {
//        // On vérifie les paramètres
//        if (id == null) {
//            throw new TechnicalException(messageSourceUtil.get(ClientKeyUtil.MESSAGE_ERROR_GET_CONTACT_ID_REQUIRED));
//        }
//
//        // On essaye de récupérer un contact correspondant à l'identifiant passé en paramètre
//        final Client client = clientDao.getClientById(id);
//        // Si aucun contact n'est trouvé, on lève une exception
//        if (client == null) {
//            throw new TechnicalException(messageSourceUtil.get(ClientKeyUtil.MESSAGE_ERROR_GET_CONTACT_NO_CONTACT_FOUND, new String[] {id.toString()}));
//        }
//        // On retourne le contact trouvé sous forme de DTO
//        return mapClient(client);
//    }
//
//    @Override
//    public List<ClientDto> getAllClients() {
//        
//        return mapClientList(clientDao.getAllClients());
//    }
//
//    private List<ClientDto> mapClientList(List<Client> allClients) {
//        final List<ClientDto> clientsDto = new ArrayList<ClientDto>();
//        for (Client client : allClients) {
//            clientsDto.add(mapClient(client));
//        }
//        return clientsDto;
//    }
//
//    private ClientDto mapClient(Client client) {
//        System.out.println(client.getEmail());
//        System.out.println(client.getFirstname());
//        System.out.println(client.getLastname());
//        System.out.println(client.getId());
//        final ClientDto clientDto = mapperDozerBean.map(client, ClientDto.class);
////        clientDto.setEmail(client.getEmail());
////        clientDto.setNom(client.getFirstname());
////        clientDto.setPrenom(client.getLastname());
//        return clientDto;
//    }
//
//    public ClientDao getClientDao() {
//        return clientDao;
//    }
//
//    public void setClientDao(ClientDao clientDao) {
//        this.clientDao = clientDao;
//    }
//
//    public MapperDozerBean getMapperDozerBean() {
//        return mapperDozerBean;
//    }
//
//    public void setMapperDozerBean(MapperDozerBean mapperDozerBean) {
//        this.mapperDozerBean = mapperDozerBean;
//    }
//
//    public MessageSourceUtil getMessageSourceUtil() {
//        return messageSourceUtil;
//    }
//
//    public void setMessageSourceUtil(MessageSourceUtil messageSourceUtil) {
//        this.messageSourceUtil = messageSourceUtil;
//    }
//
//    public IntegrityValidator getIntegrityValidator() {
//        return integrityValidator;
//    }
//
//    public void setIntegrityValidator(IntegrityValidator integrityValidator) {
//        this.integrityValidator = integrityValidator;
//    }
//
//}
